<?php

/**
*	添加版块
*
*/

//包含公共文件
include '../../common/common.php';

//接收get传值,用于确定版块
// var_dump($_POST);

$classname = trim($_POST['classname']);
$parentid    = trim($_POST['Pcategory']);

// var_dump($classname);
// var_dump($parentid);

//判断字符串长度
if (strlen($classname) > 18   ||   strlen($classname) < 3) {
	exit('只能输入3~18个字符 , 或1~6个汉字 <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
}

//判断父级版块是否为空
if ($parentid) {

	$data['parentid'] = $parentid;
} else {

	$data['parentid'] = 0;
}

$data['classname'] = "$classname";
// var_dump($data);

//插入数据库
$resCategory = myInsert($link , DB_TABLE_CG , $data);
// var_dump($resCategory);

//判断是否插入成功
if (!$resCategory) {

	exit('添加版块失败 <a href="'  . $_SERVER['HTTP_REFERER'] .'">返回上一页</a>');
}

//跳转页面
echo '添加版块成功';
header('refresh:1;url=' . $_SERVER['HTTP_REFERER']);
